package com.dexilaonian.activity;


import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dexilaonian.R;
import com.dexilaonian.adpter.RecoveryAdapter;
import com.dexilaonian.fragment.AbtainFragment;
import com.dexilaonian.fragment.YishiyongFragment;
import com.dexilaonian.fragment.YiyangFragment;
import com.dexilaonian.ui.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class IntegralActivity extends BaseActivity {

    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.base_topText)
    TextView baseTopText;
    @Bind(R.id.base_choose)
    TextView baseChoose;
    @Bind(R.id.tv_jifen)
    TextView tvJifen;
    @Bind(R.id.huode)
    TextView huode;
    @Bind(R.id.duihuan)
    TextView duihuan;
    @Bind(R.id.jifen_v1)
    View jifenV1;
    @Bind(R.id.jifen_v2)
    View jifenV2;
    @Bind(R.id.jifen_viewpager)
    ViewPager jifenViewpager;
    private List<Fragment> integral_list = new ArrayList<>();
    private RecoveryAdapter intergAdapter;

    @Override
    public int getLayoutID() {
        return R.layout.activity_integral;
    }

    @Override
    public void initView() {
        AbtainFragment abtainFragment = new AbtainFragment();
        YishiyongFragment yiyangFragment = new YishiyongFragment();
        integral_list.add(abtainFragment);
        integral_list.add(yiyangFragment);
        intergAdapter = new RecoveryAdapter(IntegralActivity.this.getSupportFragmentManager(),integral_list);
    }

    @Override
    protected void initData() {

    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        baseChoose.setVisibility(View.VISIBLE);
        baseTopText.setText("我的积分");
        init();
    }

    private void init() {
        jifenViewpager.setAdapter(intergAdapter);
        jifenViewpager.setCurrentItem(0);
        jifenViewpager.setOffscreenPageLimit(2);
        jifenViewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                TextColor(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    private void TextColor(int position) {
        if (position == 0) {
            huode.setTextColor(Color.parseColor("#009a99"));
            duihuan.setTextColor(Color.parseColor("#333333"));
            jifenV1.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
            jifenV2.setBackground(null);

        } else if (position == 1) {
            duihuan.setTextColor(Color.parseColor("#009a99"));
            huode.setTextColor(Color.parseColor("#333333"));
            jifenV1.setBackground(null);
            jifenV2.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
        }
    }

    @OnClick({R.id.base_topText,R.id.back, R.id.base_choose, R.id.huode, R.id.duihuan})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
            case R.id.base_topText:
                finish();
                break;
            case R.id.base_choose:
                break;
            case R.id.huode:
                jifenViewpager.setCurrentItem(0);
                huode.setTextColor(Color.parseColor("#009a99"));
                duihuan.setTextColor(Color.parseColor("#333333"));
                jifenV1.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
                jifenV2.setBackground(null);
                break;
            case R.id.duihuan:
                jifenViewpager.setCurrentItem(1);
                duihuan.setTextColor(Color.parseColor("#009a99"));
                huode.setTextColor(Color.parseColor("#333333"));
                jifenV1.setBackground(null);
                jifenV2.setBackground(getResources().getDrawable(R.drawable.fuwuxiangqingxiahuaxian));
                break;
        }
    }
}
